package com.fr.chart.core.glyph;

import com.fr.base.background.GradientBackground;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.DataLabelInfo;
import com.fr.chart.axis.SeriesAttrBackground;
import com.fr.chart.axis.SeriesAttrPosition;
import com.fr.chart.core.Shadow;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.SeriesAttr;
import com.fr.chart.plot.SeriesCollection;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;

public class Bar2DPlotGlyph extends BarPlotGlyph
{
  private static final long serialVersionUID = -5822126857464796926L;
  public static final String XML_TAG = "Bar2DPlotGlyph";
  private boolean isSimulation3D = false;

  public void setSimulation3D(boolean paramBoolean)
  {
    this.isSimulation3D = paramBoolean;
  }

  public boolean isSimulation3D()
  {
    return this.isSimulation3D;
  }

  public void layoutDataSeriesGlyph()
  {
    int i = 0;
    int j = getSeriesSize();
    while (i < j)
    {
      DataSeries localDataSeries = getSeries(i);
      int k = 0;
      for (int l = 0; l < localDataSeries.getDataPointCount(); ++l)
        if (!(localDataSeries.getDataPoint(l).isValueIsNull()))
          ++k;
      double[] arrayOfDouble1 = new double[k];
      double[] arrayOfDouble2 = new double[k];
      k = 0;
      for (int i1 = 0; i1 < localDataSeries.getDataPointCount(); ++i1)
      {
        DataPoint localDataPoint = localDataSeries.getDataPoint(i1);
        if (localDataPoint.isValueIsNull())
          break label323:
        ShapeGlyph localShapeGlyph = new ShapeGlyph();
        localDataPoint.setDrawImpl(localShapeGlyph);
        Rectangle2D localRectangle2D1 = getBarShape(i, i1);
        localShapeGlyph.setShape(localRectangle2D1);
        localShapeGlyph.getInfo().dealCondition(getSeriesCollection(), i);
        Rectangle2D localRectangle2D2 = (Rectangle2D)localRectangle2D1;
        double d = getDataPointPercentValue(i, i1);
        if (d > 0.0D)
        {
          arrayOfDouble1[k] = localRectangle2D2.getCenterX();
          arrayOfDouble2[k] = localRectangle2D2.getY();
        }
        else
        {
          arrayOfDouble1[k] = localRectangle2D2.getCenterX();
          arrayOfDouble2[k] = (localRectangle2D2.getY() + localRectangle2D2.getHeight());
        }
        ++k;
        if ((!(this.isHorizontal)) && (!(this.isStacked)))
          localShapeGlyph.getInfo().setShadow(new Shadow(localRectangle2D1));
        if ((isSimulation3D()) && (getSeriesCollection().getSeriesAttr(i).isContains(new SeriesAttrBackground()) == null))
        {
          Color localColor = com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[(i % com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY.length)];
          localShapeGlyph.getInfo().setBackground(new GradientBackground(localColor.brighter(), localColor, GradientBackground.TOP2BOTTOM));
        }
        dealDataPointLabelBounds(localDataPoint, i);
      }
      if ((!(isStacked())) && (!(this.isHorizontal)))
        label323: trendLineFitting(arrayOfDouble1, arrayOfDouble2, i);
      ++i;
    }
  }

  protected void dealDataPointLabelBounds(DataPoint paramDataPoint, int paramInt)
  {
    TextGlyph localTextGlyph1 = paramDataPoint.getDataLabel();
    if (localTextGlyph1 instanceof TextGlyph)
    {
      TextGlyph localTextGlyph2 = (TextGlyph)localTextGlyph1;
      SeriesAttrPosition localSeriesAttrPosition = (SeriesAttrPosition)getSeriesCollection().getSeriesCondition(new SeriesAttrPosition(), paramInt);
      Rectangle2D localRectangle2D = DataLabelInfo.preferredLabelBounds(localTextGlyph2, paramDataPoint, localSeriesAttrPosition.getPosition());
      localTextGlyph2.setBounds(localRectangle2D);
      if (getIsHorizontal())
        resetDataLabelBounds(localTextGlyph2, localSeriesAttrPosition.getPosition(), paramDataPoint.getShape().getBounds2D());
    }
  }

  private void resetDataLabelBounds(TextGlyph paramTextGlyph, int paramInt, Rectangle2D paramRectangle2D)
  {
    Dimension2D localDimension2D = paramTextGlyph.preferredDimension();
    if (paramInt == 7)
      paramTextGlyph.setBounds(new Rectangle2D.Double(paramRectangle2D.getX(), paramRectangle2D.getY() + (paramRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight()));
    else if (paramInt == 5)
      paramTextGlyph.setBounds(new Rectangle2D.Double(paramRectangle2D.getX() + paramRectangle2D.getWidth() - localDimension2D.getWidth(), paramRectangle2D.getY() + (paramRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight()));
    else if (paramInt == 6)
      paramTextGlyph.setBounds(new Rectangle2D.Double(paramRectangle2D.getX() + paramRectangle2D.getWidth(), paramRectangle2D.getY() + (paramRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight()));
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    super.draw(paramGraphics);
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Bar2DPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Bar2DPlotGlyph))
      return false;
    Bar2DPlotGlyph localBar2DPlotGlyph = (Bar2DPlotGlyph)paramObject;
    return (super.equals(localBar2DPlotGlyph));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Bar2DPlotGlyph localBar2DPlotGlyph = (Bar2DPlotGlyph)super.clone();
    return localBar2DPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("isSimulation3D", this.isSimulation3D);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "Bar2DPlotGlyph";
  }
}